package com.syt.service.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syt.service.pojo.Soc;
import com.syt.service.service.SocService;
import com.syt.service.util.LoginRequired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SocController {

    @Autowired
    SocService socService;

    /**
     * * 根据id  获取 soc
     * @param id
     * @return
     */
    @RequestMapping(value = "soc/get/{id}", method = RequestMethod.GET)
    public Soc get(@PathVariable("id") Integer id) {
        return socService.getById(id);
    }

    /**
     * 根据 页号 来获取 soc列表
     * @param
     * @return
     */
    @RequestMapping(value = "soc/list/{id}", method = RequestMethod.GET)
    public PageInfo<Soc> listsoc(@PathVariable("id") Integer id) {
        PageHelper.startPage(id, 20);
        PageInfo<Soc> pageInfo = new PageInfo<>(socService.AllListSoc());
        return pageInfo;
    }

    @LoginRequired
    @RequestMapping(value = "soc/update", method = RequestMethod.PUT)
    public Integer update(@RequestBody Soc soc) {
        return socService.updateBySelective(soc);
    }

    @LoginRequired
    @RequestMapping(value = "soc/deleteById/{id}", method = RequestMethod.DELETE)
    public Integer deleteById(@PathVariable(value = "id")Integer id) {
        return socService.deleteById(id);
    }

    @LoginRequired
    @RequestMapping(value = "soc/deleteByName/{socName}", method = RequestMethod.DELETE)
    public Integer deleteByName(@PathVariable("socName")String name) {
        return socService.deleteByName(name);
    }

    @LoginRequired
    @RequestMapping(value = "soc/add", method = RequestMethod.POST)
    public Integer add(@RequestBody Soc soc) {
        return socService.insertBySelective(soc);
    }

}
